package io.renren.modules.car.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.car.dao.CarFriendShopDao;
import io.renren.modules.car.entity.CarBaseEntity;
import io.renren.modules.car.entity.CarFriendShopEntity;
import io.renren.modules.car.entity.CarShopEntity;
import io.renren.modules.car.service.CarFriendShopService;
import io.renren.modules.car.service.CarShopService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service("carFriendShopService")
public class CarFriendShopServiceImpl extends ServiceImpl<CarFriendShopDao, CarFriendShopEntity> implements CarFriendShopService {

    @Resource
    private CarShopService carShopService;
    @Resource
    private CarFriendShopDao carFriendShopDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        IPage<CarFriendShopEntity> page = this.page(
                new Query<CarFriendShopEntity>().getPage(params),
                new QueryWrapper<CarFriendShopEntity>().eq("create_user", params.get("create_user")).orderByDesc("create_time")
        );

        List<CarShopEntity> carShopEntities = carShopService.queryList(new HashMap<>());

        page.getRecords().stream().map(m-> carShopEntities.stream().anyMatch((c -> {
            if (m.getShopId().equals(c.getId())){
                m.setShopName(c.getShopName());
            }
            return true;
        }))).collect(Collectors.toList());

        return new PageUtils(page);
    }

}
